﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WRSManagementSystem.Models
{
    public class TaskReopFake : Model.Repos.ITasksRepository
    {        
        #region IRepository<Task> Members

        static List<Model.Task> list = new List<Model.Task>() {
                new Model.Task() { Id= Guid.NewGuid(), Name = "Task1", Description="asdas" },
                new Model.Task() { Id= Guid.NewGuid(), Name = "Task2", Description="asdas" },
                new Model.Task() { Id= Guid.NewGuid(), Name = "Task3", Description="asdas" },
                new Model.Task() { Id= Guid.NewGuid(), Name = "Task4", Description="asdas" }
        };

        public int Count(System.Linq.Expressions.Expression<Func<Model.Task, bool>> expression)
        {
            throw new NotImplementedException();
        }

        public void Add(Model.Task entity)
        {
            if (entity.Project == null)
                throw new Exception("Cannot add task without project assigned");
            
            entity.Id = Guid.NewGuid();
            list.Add(entity);
        }

        public void Remove(Model.Task entity)
        {
            throw new NotImplementedException();
        }

        public void Save(Model.Task entity)
        {
            Model.Task per = list.FirstOrDefault(p => p.Id == entity.Id);
            list.Remove(per);
            list.Add(entity);
        }

        Model.Task Model.Repos.IRepository<Model.Task>.FindOne(Guid id)
        {
            return list.AsQueryable<Model.Task>().FirstOrDefault(t => t.Id == id);
        }

        public Model.Task FindOne(System.Linq.Expressions.Expression<Func<Model.Task, bool>> expression)
        {
            throw new NotImplementedException();
        }

        public bool TryFindOne(System.Linq.Expressions.Expression<Func<Model.Task, bool>> expression, out Model.Task entity)
        {
            throw new NotImplementedException();
        }

        IQueryable<Model.Task> Model.Repos.IRepository<Model.Task>.Find()
        {
            return list.AsQueryable<Model.Task>();
        }

        IQueryable<Model.Task> Model.Repos.IRepository<Model.Task>.Find(Guid id)
        {
            return list.AsQueryable<Model.Task>().Where(t => t.Id == id);
        }

        public IQueryable<Model.Task> Find(System.Linq.Expressions.Expression<Func<Model.Task, bool>> expression)
        {
            throw new NotImplementedException();
        }

        public int Count()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}